package jsi.spring;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class Main {
	public static void main(String args[]) {
		ApplicationContext context = new ClassPathXmlApplicationContext(
				new String[] { "beans.xml" });

		IIntegerWriter int1 = (IIntegerWriter) context.getBean("intwriter1");
		int1.writeInt();
		int1.writeSquare();
		ISumOfSquaresWriter sint1 = (ISumOfSquaresWriter) context
				.getBean("sumwriter1");
		sint1.sumOfSquares();

//		ApplicationContext context = new ClassPathXmlApplicationContext(
//				new String[] { "beans.xml" });
		OsobaDao dao = (OsobaDao) context.getBean("osobaDao");
		System.out.println("dao: " + dao);
		Osoba o = (Osoba) context.getBean("osoba");
		System.out.println("o: " + o + " " + o.getImie() +" " + o.getClass());
		Osoba o2 = dao.findOsobaByName(o.getImie());
		if (o2 != null){
			System.out.println("nazwisko: " + o2.getNazwisko() + ".");
			dao.saveOsoba(o2);
		}
		else {
			System.out.println("nie ma w bazie osoby o nazwisku " + o.getNazwisko());
			Osoba o3 = new Osoba(o);
		//	Osoba o3 = o;
			System.out.println("nazw " + o.getNazwisko() + " o3.nazw " + o3.getNazwisko());
			
			dao.saveOsoba(o3);
		}	
	}
}